<%args>
  $file
  $key
</%args>
<%init>
my $img_file_name = $file;
$img_file_name =~ s%^$TRFLP::data_path/%%;
$img_file_name =~ s%/%:%g;
$img_file_name = "$TRFLP::cache/$img_file_name.png";
my $peak_file_name = "$file.peak";

my $image;

if ( not -f $img_file_name or File::stat::stat($peak_file_name)->mtime > File::stat::stat($img_file_name)->mtime ) {
  $image = Plot::plot_heatmap(-file => $file, -key => $key);
  open IMG, ">$img_file_name";
  print IMG $image;
  close IMG;
}
else {
  $image = `cat $img_file_name`;
}

$m->print($image);
$m->abort(200);
</%init>
<%flags>
  inherit => 'syshandler'
</%flags>
